package cn.wygandwdn.common.message;

import java.util.HashMap;
import java.util.Map;

/**
 * @description:
 * @author: WYG
 * @time: 2021/10/25 10:30
 */

public abstract class Message {

    /**
     * 消息类型
     */
    private int messageType;
    /**
     * 请求序号
     */
    private long sequenceId;

    public long getSequenceId() {
        return sequenceId;
    }

    public void setSequenceId(long sequenceId) {
        this.sequenceId = sequenceId;
    }

    /**
     * 获取对象类型
     * @return  对象类型
     */
    public abstract int getMessageType();

    public static Class<? extends Message> getMessageClass(int messageType) {
        return messageCached.get(messageType);
    }

    public static final int RpcRequestMessage = 0;
    public static final int RpcResponseMessage = 1;
    public static final int Ping = 2;
    public static final int Pong = 3;

    private static final Map<Integer, Class<? extends Message>> messageCached = new HashMap<>();

    static {
        messageCached.put(RpcRequestMessage, RpcRequest.class);
        messageCached.put(RpcResponseMessage, RpcResponse.class);
        messageCached.put(Ping, PingMessage.class);
        messageCached.put(Pong, PongMessage.class);
    }

}
